// import { login, logout, getInfo } from '@/api/login'
// import { getToken, setToken, removeToken } from '@/utils/auth'
import Layout from "../../views/layout/Layout"
const user = {
  state: {
    // token: getToken(),
    userName: '',
    password: "",
    avatar: '',
    userlist: [],
    roles: "",
    userid:"",
    roleMap: [
      [
        {
          path: '/userCharge',
          component: Layout,
          children: [
            {
              path: 'userCharge',
              name: 'userCharge',
              meta: { title: '（a）用户管理', icon: 'example', roles: 1 },
              component: () => import('@/views/userCharge/userCharge')
            }
          ]
        },

        {
          path: '/workDay',
          component: Layout,
          children: [
            {
              path: 'workDay',
              name: 'workDay',
              component: () => import('@/views/workDay/workDay'),
              meta: { title: '（a）工作日管理', icon: 'form', roles: 1 }
            }
          ]
        },
        {
          path: '/roleCharge',
          component: Layout,
          children: [
            {
              path: 'roleCharge',
              name: 'roleCharge',
              component: () => import('@/views/roleCharge/roleCharge'),
              meta: { title: '（a）角色管理', icon: 'example', roles: 1 }
            }
          ]
        },
        { path: '*', redirect: '/404', hidden: true }
      ], [
        {
          path: '/unusualAttendance',
          component: Layout,
          children: [
            {
              path: 'unusualAttendance',
              name: 'unusualAttendance',
              component: () => import('@/views/unusualAttendance/unusualAttendance'),
              meta: { title: '(上领)异常考勤处理', icon: 'table', roles: 2 }
            }
          ]
        },
        {
          path: '/attendanceRecord',
          component: Layout,
          children: [
            {
              path: 'attendanceRecord',
              name: 'attendanceRecord',
              component: () => import('@/views/attendanceRecord/attendanceRecord'),
              meta: { title: '(上领)请假审批', icon: 'form', roles: 2 }
            }
          ]
        },
        { path: '*', redirect: '/404', hidden: true }
      ], [
        {
          path: '/dayOff',
          component: Layout,
          children: [
            {
              path: 'dayOffCheck',
              name: 'dayOffCheck',
              component: () => import('@/views/dayOff/dayOffCheck'),
              meta: { title: '(领)员工考勤', icon: 'form', roles: 2 }
            }
          ]
        },
        { path: '*', redirect: '/404', hidden: true }
      ], [
        {
          path: '/dayOff',
          component: Layout,
          children: [
            {
              path: 'dayOffApplication',
              name: 'dayOffApplication',
              component: () => import('@/views/dayOff/dayOffApplication'),
              meta: { title: '(员工)请假申请', icon: 'form', roles: 3 }
            }
          ]
        },
        {
          path: '/attendanceMaintenance',
          component: Layout,
          children: [
            {
              path: 'attendanceMaintenance',
              name: 'attendanceMaintenance',
              component: () => import('@/views/attendanceMaintenance/attendanceMaintenance'),
              meta: { title: '考勤异常维护', icon: 'form', roles: 3 }
            }
          ]
        },
        {
          path: '/sign',
          component: Layout,
          children: [
            {
              path: 'sign',
              name: 'sign',
              component: () => import('@/views/sign/sign'),
              meta: { title: '(员工)签到管理', icon: 'form', roles: 3 }
            }
          ]
        },
        { path: '*', redirect: '/404', hidden: true }
      ]
    ]
  },

  mutations: {
    // SET_TOKEN: (state, token) => {
    //   state.token = token
    // },
    SET_NAME: (state, name) => {
      state.userName = name
    },
    SET_PASSWORD: (state, password) => {
      state.password = password
    },
    // SET_AVATAR: (state, avatar) => {
    //   state.avatar = avatar
    // },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    },
    user_id: (state, userid) => {
      state.userid = userid
    },
    user_List:(state,userlist) =>{
      state.userlist = userlist
    }
  },

  actions: {
    // 登录
    Login({ commit }, userInfo) {
      const username = userInfo.username.trim()
      // return new Promise((resolve, reject) => {
      // login(username, userInfo.password).then(response => {
      // const data = response.data
      // setToken(data.token)
      commit('SET_NAME', username)
      commit('SET_PASSWORD', userInfo.password)
      // console.log(response)
      //   resolve()
      // }).catch(error => {
      //   reject(error)
      // })
      // })
    },

    // 获取用户信息
    // GetInfo({ commit, state }) {
    //   return new Promise((resolve, reject) => {
    //     this.$axios
    //       .post(
    //         "http://10.5.116.60:8088/login",
    //         qs.stringify({
    //           loginName: this.loginForm.username,
    //           password: this.loginForm.password
    //         }),
    //         {
    //           headers: {
    //             "Content-Type": "application/x-www-form-urlencoded"
    //           }
    //         }
    //       )
    //       .then(res => {
    //         // this.loading = false;
    //         // console.log(res);
    //         // this.commit("SET_NAME",res.role)
    //         // this.$store.commit('SET_ROLES', res.data.RoleId)
    //         const data = res.data
    //         if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
    //           commit('SET_ROLES', data.RoleId)
    //         } else {
    //           reject('getInfo: roles must be a non-null array !')
    //         }
    //         this.$store
    //           .dispatch("Login", this.loginForm)

    //       })
    //       .catch(function (err) {
    //         console.log(err);
    //       });

        // getInfo(state.token).then(response => {
        //   const data = response.data
        //   if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
        //     commit('SET_ROLES', data.roles)
        //   } else {
        //     reject('getInfo: roles must be a non-null array !')
        //   }
        //   commit('SET_NAME', data.name)
        //   commit('SET_AVATAR', data.avatar)
        //   resolve(response)
        // }).catch(error => {
        //   reject(error)
        // })
    //   })
    // },

    // 登出
    // LogOut({ commit, state }) {
    //   return new Promise((resolve, reject) => {
    //     logout(state.token).then(() => {
    //       commit('SET_TOKEN', '')
    //       commit('SET_ROLES', [])
    //       // removeToken()
    //       resolve()
    //     }).catch(error => {
    //       reject(error)
    //     })
    //   })
    // },

    // 前端 登出
    FedLogOut({ commit }) {
      return new Promise(resolve => {
        commit('SET_TOKEN', '')
        // removeToken()
        resolve()
      })
    }
  }
}

export default user
